package com.shouhuobao.take.active.adapter;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.shouhuobao.station.R;
import com.shouhuobao.take.model.ActiveBean;
import com.shouhuobao.take.utils.StringUtils;

import java.util.ArrayList;

import droid.frame.activity.base.BaseAdapterExt;

/**
 * Created by joker on 2017/9/21.
 * 活动适配器
 */
public class ActiveAdapter extends BaseAdapterExt<ActiveBean> {

    public ActiveAdapter(ArrayList<ActiveBean> items, Activity context) {
        super(items, context);
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        if (hasEmptyView()) {
            return super.getView(position, convertView, parent);
        }
        ViewHolder holder;
        if (convertView == null || convertView.getTag() == null) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.adapter_active, parent, false);
            holder.activeItemLayout = (LinearLayout) convertView.findViewById(R.id.item_layout);
            holder.activeTitleTV = (TextView) convertView.findViewById(R.id.active_title_tv);
            holder.activeDateTV = (TextView) convertView.findViewById(R.id.active_date_tv);
            holder.activeTipsTV = (TextView) convertView.findViewById(R.id.active_tips_tv);
            holder.activeRankTV = (TextView) convertView.findViewById(R.id.user_rank_tv);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        final ActiveBean item = items.get(position);
        if (item.getType()==1){
            holder.activeItemLayout.setBackgroundResource(R.drawable.activity_receive_bj);
        }else {
            holder.activeItemLayout.setBackgroundResource(R.drawable.activity_sent_bj);
        }
        holder.activeTitleTV.setText(item.getTitle());
        holder.activeDateTV.setText(item.getDate());
        holder.activeTipsTV.setText(item.getContent());
        if (StringUtils.isEmpty(item.getMyrank())){
            holder.activeRankTV.setVisibility(View.GONE);
        }else {
            holder.activeRankTV.setVisibility(View.VISIBLE);
            holder.activeRankTV.setText(item.getMyrank());
        }
        return convertView;
    }

    private class ViewHolder {
        LinearLayout activeItemLayout;
        TextView activeTitleTV;//活动标题
        TextView activeDateTV;//操作的金额
        TextView activeTipsTV;//活动提示
        TextView activeRankTV;//自己活动中排名
    }
}
